#include <moying_comm_lib/moying_commu.h>
#include <moying_comm_lib/moying_commu_base.h>
#include <moying_comm_lib/request.h>
#include <moying_comm_lib/reply.h>
#include <moying_comm_lib/subscribe.h>
#include <moying_comm_lib/publish.h>
#include <iostream>

namespace moying
{
namespace communication
{

std::string moying_commu_lib_version = "0.0.1";

std::shared_ptr<MoyingCommuInterface> MoyingCommuFactory::newSocket(
    MoyingCommuType type,
    const std::string &ip,
    const unsigned int port,
    const std::string &identity)
{
  std::shared_ptr<MoyingCommuInterface> obj = nullptr;
  std::string url = "tcp://" + ip + ":" + std::to_string(port);
  try{
      if (MoyingCommuType::CLIENT_REQUEST == type)
        obj = std::make_shared<MoyingCommuRequest>(url, identity);
      if (MoyingCommuType::SERVER_REPLY == type)
        obj = std::make_shared<MoyingCommuReply>(url, identity);
      if (MoyingCommuType::CLIENT_SUBSCRIBE == type)
        obj = std::make_shared<MoyingCommuSubscribe>(url, identity);
      if (MoyingCommuType::SERVER_PUBLISH == type)
        obj = std::make_shared<MoyingCommuPublish>(url, identity);
  }catch(zmq::error_t e){
      std::cout<< "create socket failed: "<<e.what()<<" errnum:"<<e.num()<<std::endl;
  }

  return obj;
}

} // namespace communication
} // namespace moying
